package com.ljfiction.book.activitys;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.ImageView;

import com.ljfiction.book.R;
import com.ljfiction.book.fragment.transactionrecord.TansetionDingyueFragment;
import com.ljfiction.book.fragment.transactionrecord.TransectionPurseFragment;
import com.ljfiction.book.fragment.transactionrecord.TransetionDashangFragment;
import com.ljfiction.book.fragment.transactionrecord.TransetionGoldionFragment;
import com.ljfiction.book.fragment.transactionrecord.TranstionXiaomjFragment;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class TransactionRecordActivity extends BaseActivity {

    @BindView(R.id.back_transaction)
    ImageView backTransaction;

    @BindView(R.id.mytransactionviewpager)
    ViewPager mytransactionviewpager;
    @BindView(R.id.mytransectionxtablayout)
    TabLayout mytransectionxtablayout;

    private ArrayList<Fragment> fragments = new ArrayList<>();
    private ArrayList<String> tabTitles = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_transaction_record);
        ButterKnife.bind(this);
        intview();
    }

    @OnClick(R.id.back_transaction)
    public void onViewClicked() {
        goBack();
    }

    private void intview() {
        tabTitles.add("充值记录");
        tabTitles.add("订阅记录");
        tabTitles.add("金椒记录");
        tabTitles.add("打赏记录");
        tabTitles.add("小米椒记录");
        fragments.add(new TransectionPurseFragment());
        fragments.add(new TansetionDingyueFragment());
        fragments.add(new TransetionGoldionFragment());
        fragments.add(new TransetionDashangFragment());
        fragments.add(new TranstionXiaomjFragment());

        /**
         * 预加载
         */
        mytransactionviewpager.setOffscreenPageLimit(fragments.size());
        /**
         * 设置适配器
         */
        mytransactionviewpager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }
            @Override
            public int getCount() {
                return fragments.size();
            }
            @Override
            public CharSequence getPageTitle(int position) {
                return tabTitles.get(position);
            }
        });
        mytransectionxtablayout.setupWithViewPager(mytransactionviewpager);
    }

}
